//
//  RequestUrl.m
//  Project_ZFR_MUSIC
//
//  Created by 张福润 on 16/2/25.
//  Copyright © 2016年 张福润. All rights reserved.
//

#import "RequestUrl.h"
#import "MusicModel.h"
#define MUSICURL @"http://project.lanou3g.com/teacher/UIAPI/MusicInfoList.plist"
static RequestUrl *re=nil;
@implementation RequestUrl
+(instancetype)shareRequestUrl{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        re=[[RequestUrl alloc]init];
    });
    return re;
}

-(void)requestMusicWithSeccess:(void (^)(id))success faile:(void (^)(NSError *))faile{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSArray *arr=[NSArray arrayWithContentsOfURL:[NSURL URLWithString:MUSICURL]];
        if(arr.count==0){
            NSError *err=[NSError errorWithDomain:@"请求出错" code:0 userInfo:nil];
            dispatch_async(dispatch_get_main_queue(), ^{
                faile(err);
                return ;
            });
        }
        self.arrModel=[NSMutableArray array];
        for (NSDictionary *dic in arr) {
            MusicModel *model=[[MusicModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [self.arrModel addObject:model];
        }
        if(success){
            dispatch_async(dispatch_get_main_queue(), ^{
                success(self.arrModel);
            });
        }
        
        
    });
}
@end
